package com.regentsoft.cloudback.operateAdmin.controller;

import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.regentsoft.cloudback.base.BaseResp;
import com.regentsoft.cloudback.base.ResponseCode;
import com.regentsoft.cloudback.operateAdmin.entity.Company;
import com.regentsoft.cloudback.operateAdmin.service.CompanyService;
import com.regentsoft.cloudback.vo.req.CompanyApplicationAddReq;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 
 * @author czd
 *
 * @date 2017年11月25日
 *
 * @version 1.0
 */
@Api
@RestController
@RequestMapping("manager/companyApplication/")
public class CompanyApplicationController {
	@Autowired
	private CompanyService companyService;
	
	@ApiOperation(value = "添加或修改收银信息", httpMethod = "POST", response = BaseResp.class, notes = "添加或修改收银信息")
	@RequestMapping(value="addOrEditCompanyApplication")
    public BaseResp addOrEditCompanyApplication(@RequestParam String token,@RequestBody CompanyApplicationAddReq req) throws Exception {
		BaseResp resp  = new BaseResp();
		
		if(req.getCode()==null) {
			resp.setCode(ResponseCode.PARAMETERERR);
			resp.setMessage("填写数据不完整");
			return resp;
		}
		Company company = new Company();
		try {
			company.setUpdateTime(new Date());
			company.setCode(req.getCode());
			company.setPosIp(req.getPosIp());
			companyService.updateByCode(company);
		} catch (Exception e) {
			throw new RuntimeException(e.getMessage(),e);
		}
		resp.setCode(ResponseCode.SUCCESS);
        return resp;
    }
}
